package Card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Admin
 * Date: 2022-04-28
 * Time: 19:01
 */


public class Main {
    public static final String[] Suit = {"♠", "♥", "♣", "♦"};
    public static List<Card> BuyCard() {
        List<Card> list = new ArrayList<Card>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j < 13; j++) {
                String suit = Suit[i];
                Card card= new Card(suit,j);
                list.add(card);
            }
        }
        return list;
    }
    public static void Shuffle(List<Card> cardList ) {
        for (int i = cardList.size()-1; i > 0 ; i--) {
            Random rand = new Random();
            int index = rand.nextInt(i);
            Swap(cardList,i ,index);
        }
    }

    public static void Swap(List<Card> list,int i,int j) {
        Card cmp = list.get(i);
        list.set(i,list.get(j));
        list.set(j,cmp);
    }

    public static void main(String[] args) {
        List<Card> list = BuyCard();
        System.out.println(list);

        Shuffle(list);
        System.out.println(list);

        List<List<Card>> list1= new ArrayList<>();
        list1.add(new ArrayList<Card>());
        list1.add(new ArrayList<Card>());
        list1.add(new ArrayList<Card>());
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 5; j++) {
                Card card = list.remove(0);
                list1.get(i).add(card);
            }
        }
        System.out.println("第一个人的牌");
        System.out.println(list1.get(0));
        System.out.println("第二个人的牌");
        System.out.println(list1.get(1));
        System.out.println("第三个人的牌");
        System.out.println(list1.get(2));
        System.out.println("最后剩余的牌：");
        System.out.println(list);
    }
}